/* scrogui.hxx */

#ifndef __SCRO_GUI_H_
#define __SCRO_GUI_H_


#include <SDL/SDL.h>

#include <SDL/SDL_ttf.h>
#include <SDL/SDL_gfxPrimitives.h>
#include <SDL/SDL_image.h>

#include "../src/scro.hxx"
#include "../src/utils.hxx"
#include "../src/sdlfunc.hxx"

#define SCROGUI_BUTTON_PRESSED 0x1

#define SCROGUI_DEFAULT_FONT "data/fonts/VeraMono.ttf"
#define SCROGUI_DEFAULT_FONTSIZE 12

#define SCROGUI_VIDEO_MODE VIDEO_MODE
#define SCROGUI_DEFAULT_FADE 120

class gui_element
{
	public:
		gui_element(const char * element_name, unsigned int element_type, char * element_string, char * element_value, unsigned int element_x_offset, unsigned int element_y_offset, unsigned int element_order, TTF_Font * font, SDL_Color pane_col, SDL_Color gui_col, unsigned int (*function_pointer)(unsigned int), unsigned int max_length);
        gui_element(const char * element_name, unsigned int element_type, SDL_Surface * image, unsigned int element_x_offset, unsigned int element_y_offset, unsigned int element_order, SDL_Color pane_col, unsigned int(*function_pointer)(unsigned int));
		~gui_element();
	

//	private:
		gui_element * next_element;
	
		unsigned int type;
		char * label;
		char * value;
		SDL_Surface * rendered_element;
	
		SDL_Rect position;
	
		unsigned int order;
		
		unsigned int (*button_callback)(unsigned int);
		
		unsigned int max_len;
		
		char name[30];
		
		unsigned int flags;
};


class scrogui
{
	public:
		scrogui(SDL_Rect * newpane, SDL_Surface * target, char * title);
		~scrogui();
		
		unsigned int addLabel(const char * el_name, char * string, unsigned int x_offset, unsigned int y_offset);
		unsigned int addImage(const char * el_name, SDL_Surface * image, unsigned int x_offset, unsigned int y_offset);
		unsigned int addImageButton(const char * el_name, SDL_Surface * image, unsigned int x_offset, unsigned int y_offset, unsigned int(*function)(unsigned int));
		unsigned int addButton(const char * el_name, char * string, unsigned int x_offset, unsigned int y_offset, unsigned int(*function)(unsigned int));
		unsigned int addInput(const char * el_name, char * string, char * value, unsigned int x_offset, unsigned int y_offset, unsigned int max_length, unsigned int type);
		unsigned int redrawGUI(SDL_Surface * spec_target);
		unsigned int redrawPane(SDL_Surface * spec_target);
		SDL_Surface * returnDrawnSurface(void);
		unsigned int highlightElement(SDL_Rect * highlight_rect);
		unsigned int unHighlightElement(SDL_Rect * highlight_rect);
		unsigned int guiEventHandler(SDL_Event * gui_event);
		
		unsigned int setAlpha(unsigned int alpha);
		unsigned int setBlank(unsigned int blank);
		
		unsigned int get_flags_of_object(const char * name);
		unsigned int set_flags_of_object(const char * name, unsigned int flags_to_set);
		
		unsigned int updateImage(const char * name, SDL_Surface * image);
		unsigned int updateString(const char * el_name, char * new_string);
		unsigned int updateValue(const char * el_name, char * new_string);
		
		char * returnValue(const char * el_name);
		
		unsigned int message_box(char * title, char * string, unsigned int type);


		
	private:
	
		unsigned int addElement(const char * el_name, unsigned int type, char * string, char * value, unsigned int x_offset, unsigned int y_offset, unsigned int(*function)(unsigned int), unsigned int max_length);
        unsigned int addElement(const char * el_name, unsigned int type, SDL_Surface * picture, unsigned int x_offset, unsigned int y_offset, unsigned int(*function)(unsigned int));
		unsigned int handleInput(gui_element * input_element);
		unsigned int redrawHandleInput(gui_element * input_element, char * temp_string);
		unsigned int changeInputValue(gui_element * input_element, char * temp_string);
	
		SDL_Rect * gui_pane;
		TTF_Font * gui_font;
		SDL_Color gui_color;
		SDL_Color gui_highlight_color;
		SDL_Color pane_color;
		SDL_Color pane_border_color;
		SDL_Color pane_title_bg_color;
		SDL_Color button_color;
		SDL_Surface * gui_surface;
		gui_element * first_element;
		char * gui_title;
                
		unsigned int gui_title_bar_height;

		unsigned int gui_alpha;
		unsigned int blank_screen;
	
		unsigned int tab_position;
		/* fixme: function pointer */
};


#endif
